home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 12
/
Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso
/
Aminet
/
gfx
/
show
/
gs_src_amiga.lha
/
gp_amiga.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-03-05
|
13KB
|
580 lines
/* Copyright (C) 1989, 1992, 1993, 1994 Aladdin Enterprises. All rights reserved.
This file is part of Aladdin Ghostscript.
Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
or distributor accepts any responsibility for the consequences of using it,
or for whether it serves any particular purpose or works at all, unless he
or she says so in writing. Refer to the Aladdin Ghostscript Free Public
License (the "License") for full details.
Every copy of Aladdin Ghostscript must include a copy of the License,
normally in a plain ASCII text file named PUBLIC. The License grants you
the right to copy, modify and redistribute Aladdin Ghostscript, but only
under certain conditions described in the License. Among other things, the
License requires that the copyright notice and this notice be preserved on
all copies.
*/
/* gp_amiga.c */
/* Amiga-specific routines for Ghostscript */
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include <dos/dosextens.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include "string_.h"
#include "gx.h"
#include "gsexit.h"
#include "gp.h"
#include "time_.h"
#include <signal.h>
#include <stdio.h>
/* Library routines not declared in a standard header */
extern char *getenv(P1(const char *));
/* Because of inconsistent (and sometimes incorrect) header files, */
/* we must omit the argument list. */
#ifdef IXEMUL
extern FILE *popen( P2(const char *, const char *) );
extern int pclose(P1(FILE *));
#endif
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Library *LayersBase,
*IFFParseBase,
*AslBase,
*UtilityBase;
#ifdef IXEMUL
const char gp_null_file_name[] = "/NIL";
const char gp_current_directory_name[] = ".";
#else
const char gp_null_file_name[] = "NIL:";
const char gp_current_directory_name[] = "";
#endif
/* Cleanup routine, as called by atexit() trap */
void
cleanup()
{
extern void devcleanup();
devcleanup();
if(IFFParseBase)
{
CloseLibrary(IFFParseBase);
IFFParseBase = NULL;
}
if(AslBase)
{
CloseLibrary(AslBase);
AslBase = NULL;
}
if(UtilityBase)
{
CloseLibrary(UtilityBase);
UtilityBase = NULL;
}
if(LayersBase)
{
CloseLibrary(LayersBase);
LayersBase = NULL;
}
if(GfxBase)
{
CloseLibrary((struct Library *)GfxBase);
GfxBase = NULL;
}
if(IntuitionBase)
{
CloseLibrary((struct Library *)IntuitionBase);
IntuitionBase = NULL;
}
}
void
signal_handler(int signal)
{
fprintf(stderr,"*** BREAK: Ghostscript\a\n");
exit(1);
}
/* Do platform-dependent initialization. */
void
gp_init(void)
{
atexit(cleanup);
signal(SIGINT,signal_handler);
if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)))
{
perror("Ghostscript: cannot open intuition.library v37");
exit(20);
}
if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37)))
{
perror("Ghostscript: cannot open graphics.library v37");
exit(20);
}
if(!(LayersBase = OpenLibrary("layers.library",37)))
{
perror("Ghostscript: cannot open layers.library v37");
exit(20);
}
if(!(UtilityBase = OpenLibrary("utility.library",37)))
{
perror("Ghostscript: cannot open utility.library v37");
exit(20);
}
if(!(IFFParseBase = OpenLibrary("iffparse.library",37)))
{
perror("Ghostscript: cannot open iffparse.library v37");
exit(20);
}
AslBase = OpenLibrary("asl.library",38);
}
/* Do platform-dependent cleanup. */
void
gp_exit(int exit_status, int code)
{
cleanup();
}
/* ADDED by JvdW for GS3.51 */
/* Exit the program. */
void
gp_do_exit(int exit_status)
{ exit(exit_status);
}
/* Read the current user CPU time (in seconds) */
/* and fraction (in nanoseconds). */
void
gp_get_usertime(long *pdt)
{
#if use_times_for_usertime
LONG secs, micros;
CurrentTime(&secs, µs);
pdt[0] = secs;
pdt[1] = micros*1000;
#else
gp_get_clock(pdt); /* Use an approximation on other hosts. */
#endif
}
/* /ADDED */
/* ------ Miscellaneous ------ */
/* Get the string corresponding to an OS error number. */
/* Unix systems support this so inconsistently that we don't attempt */
/* to figure out whether it's available. */
const char *
gp_strerror(int errnum)
{ return NULL;
}
/* ------ Date and time ------ */
/* Read the current date (in days since Jan. 1, 1980) */
/* and time (in milliseconds since midnight). */
void
gp_get_clock(long *pdt)
{
struct DateStamp Date;
LONG secs, micros;
CurrentTime(&secs, µs);
pdt[0] = secs;
pdt[1] = micros*1000;
DateStamp(&Date);
/*
pdt[0] = Date . ds_Days + 2 * 365;
pdt[1] = (Date . ds_Minute * 60 + Date . ds_Tick / TICKS_PER_SECOND) * 1000;
*/
}
/* ------ Screen management ------ */
/* Get the environment variable that specifies the display to use. */
const char *
gp_getenv_display(void)
{ return getenv("DISPLAY");
}
/* ------ Printer accessing ------ */
/* Open a connection to a printer. A null file name means use the */
/* standard printer connected to the machine, if any. */
/* "|command" opens an output pipe. */
/* Return NULL if the connection could not be opened. */
FILE *
gp_open_printer(char *fname, int binary_mode)
{
#ifndef IXEMUL
return
(strlen(fname) == 0 ?
gp_open_scratch_file(gp_scratch_file_name_prefix, fname, "w") :
fname[0] == '|' ?
NULL :
fopen(fname, "w"));
#else
return
(strlen(fname) == 0 ?
gp_open_scratch_file(gp_scratch_file_name_prefix, fname, "w") :
fname[0] == '|' ?
popen(fname + 1, "w") :
fopen(fname, "w"));
#endif
}
/* Close the connection to the printer. */
void
gp_close_printer(FILE *pfile, const char *fname)
{
#ifndef IXEMUL
fclose(pfile);
#else
if ( fname[0] == '|' )
pclose(pfile);
else
fclose(pfile);
#endif
}
/* ------ File name syntax ------ */
/* Define the character used for separating file names in a list. */
const char gp_file_name_list_separator = ',';
/* Define the default scratch file name template. */
const char gp_scratch_file_name_prefix[] = "T:gs_";
/* Define the string to be concatenated with the file mode */
/* for opening files without end-of-line conversion. */
const char gp_fmode_binary_suffix[] = "";
/* Define the file modes for binary reading or writing. */
const char gp_fmode_rb[] = "r";
const char gp_fmode_wb[] = "w";
/* Create and open a scratch file with a given name prefix. */
/* Write the actual file name at fname. */
FILE *
gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
{
#ifndef IXEMUL
char *temp;
char temp2[100];
struct Task *thistask;
LONG secs, micros;
#endif
strcpy(fname,prefix);
/* Prevent trailing X's in path from being converted by mktemp. */
if ( *fname != 0 && fname[strlen(fname) - 1] == 'X' )
strcat(fname, "-");
#ifdef IXEMUL
strcat(fname, "XXXXXX");
#else
CurrentTime(&secs, µs);
sprintf(temp2,"%lx",FindTask(NULL));
strcat(fname, temp2);
#endif
#ifdef IXEMUL
mktemp(fname);
#endif
return fopen(fname, mode);
}
/* Answer whether a file name contains a directory/device specification, */
/* i.e. is absolute (not directory- or device-relative). */
int
gp_file_name_is_absolute(const char *fname, uint len)
{
int i;
for(i = 0 ; i < len ; i++)
{
if(fname[i] == ':')
return(1);
}
return(0);
}
/* Answer the string to be used for combining a directory/device prefix */
/* with a base file name. The file name is known to not be absolute. */
const char *
gp_file_name_concat_string(const char *prefix, uint plen, const char *fname, uint len)
{
#ifdef IXEMUL
if(plen > 0 && (prefix[plen - 1] == '/' || prefix[plen - 1] == ':'))
return("");
else
return("/");
#else
if(plen > 0)
if(prefix[plen - 1] == '/' || prefix[plen - 1] == ':')
return("");
else
return("/");
else
return("");
#endif
}
/* ------ File operations ------ */
/* If the file given by fname exists, fill in its status and return 1; */
/* otherwise return 0. */
int
gp_file_status(const char *fname, struct stat *pstat)
{
if ( stat((char *)fname, pstat) < 0 ) return 0;
return 1;
}
/* ADDED by JvdW for GS3.51 */
/* Open a file with the given name, as a stream of uninterpreted bytes. */
FILE *
gp_fopen(const char *fname, const char *mode)
{ return fopen(fname, mode);
}
/* /ADDED */
/* ------ File enumeration ------ */
/****** THIS IS NOT SUPPORTED ON UNIX SYSTEMS. ******/
/* Amazingly enough, there is no standard Unix library routine */
/* for enumerating the files matching a pattern, */
/* or even for enumerating (conveniently) the files in a directory. */
struct file_enum_s {
char *pattern;
int first_time;
const gs_memory_t *mprocs;
};
/* Initialize an enumeration. NEEDS WORK ON HANDLING * ? \. */
file_enum *
gp_enumerate_files_init(const char *pat, uint patlen,
gs_memory_t *mprocs)
{ file_enum *pfen = (file_enum *)gs_alloc_bytes(mprocs,sizeof(file_enum), "gp_enumerate_files");
char *pattern;
if ( pfen == 0 ) return 0;
pattern = gs_alloc_bytes(mprocs,patlen + 1,"gp_enumerate_files(pattern)");
if ( pattern == 0 ) return 0;
memcpy(pattern, pat, patlen);
pattern[patlen] = 0;
pfen->pattern = pattern;
pfen->mprocs = mprocs;
pfen->first_time = 1;
return pfen;
}
/* Enumerate the next file. */
/* PUNT: JUST RETURN THE PATTERN. */
uint
gp_enumerate_files_next(file_enum *pfen, char *ptr, uint maxlen)
{ if ( pfen->first_time )
{ char *pattern = pfen->pattern;
uint len = strlen(pattern);
pfen->first_time = 0;
if ( len > maxlen )
return maxlen + 1;
strcpy(ptr, pattern);
return len;
}
return -1;
}
/* Clean up the file enumeration. */
void
gp_enumerate_files_close(file_enum *pfen)
{ const gs_memory_t *mprocs = pfen->mprocs;
gs_free_object(mprocs,pfen->pattern,"gp_enumerate_files_close(pattern)");
gs_free_object(mprocs,(char *)pfen,"gp_enumerate_files_close");
}
/***************************************************************************/
/* Functions from ixemul.library source which aren't in Libnix */
/***************************************************************************/
#ifndef IXEMUL
/***************************************************************************/
/* modf.c */
/***************************************************************************/
#include <proto/mathieeedoubbas.h>
/*
* modf(value, iptr): return fractional part of value, and stores the
* integral part into iptr (a pointer to double).
*/
double
modf (double value, double *iptr)
{
/* if value negative */
if (IEEEDPTst (value) < 0)
{
/* in that case, the integer part is calculated by ceil() */
*iptr = IEEEDPCeil (value);
return IEEEDPSub (*iptr, value);
}
else
{
/* if positive, we go for the floor() */
*iptr = IEEEDPFloor (value);
return IEEEDPSub (value, *iptr);
}
}
/***************************************************************************/
/* frexp.c */
/***************************************************************************/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)frexp.c 5.2 (Berkeley) 3/9/86";
#endif LIBC_SCCS and not lint
#define KERNEL
/*#include "ixemul.h"*/
/*
* the call
* x = frexp(arg,&exp);
* must return a double fp quantity x which is <1.0
* and the corresponding binary exponent "exp".
* such that
* arg = x*2^exp
* if the argument is 0.0, return 0.0 mantissa and 0 exponent.
*/
double
frexp(double x, int *i)
{
int neg;
int j;
j = 0;
neg = 0;
if (x < 0)
{
x = -x;
neg = 1;
}
if (x >= 1.0)
while(x >= 1.0)
{
j = j+1;
x = x/2;
}
else if(x < 0.5 && x != 0.0)
while(x < 0.5)
{
j = j-1;
x = 2*x;
}
*i = j;
if (neg) x = -x;
return x;
}
/***************************************************************************/
/* ldexp.c */
/***************************************************************************/
/*
* ldexp returns the quanity "value" * 2 ^ "exp"
*
* For the mc68000 using IEEE format the double precision word format is:
*
* WORD N => SEEEEEEEEEEEMMMM
* WORD N+1 => MMMMMMMMMMMMMMMM
* WORD N+2 => MMMMMMMMMMMMMMMM
* WORD N+3 => MMMMMMMMMMMMMMMM
*
* Where: S => Sign bit
* E => Exponent
* X => Ignored (set to 0)
* M => Mantissa bit
*
* NOTE: Beware of 0.0; on some machines which use excess 128 notation for the
* exponent, if the mantissa is zero the exponent is also.
*
*/
#define MANT_MASK 0x800FFFFF /* Mantissa extraction mask */
#define ZPOS_MASK 0x3FF00000 /* Positive # mask for exp = 0 */
#define ZNEG_MASK 0x3FF00000 /* Negative # mask for exp = 0 */
#define EXP_MASK 0x7FF00000 /* Mask for exponent */
#define EXP_SHIFTS 20 /* Shifts to get into LSB's */
#define EXP_BIAS 1023 /* Exponent bias */
union dtol
{
double dval;
int ival[2];
};
double
ldexp (value, exp)
double value;
int exp;
{
union dtol number;
int *iptr, cexp;
if (value == 0.0)
return (0.0);
else
{
number.dval = value;
iptr = &number.ival[0];
cexp = (((*iptr) & EXP_MASK) >> EXP_SHIFTS) - EXP_BIAS;
*iptr &= ~EXP_MASK;
exp += EXP_BIAS;
*iptr |= ((exp + cexp) << EXP_SHIFTS) & EXP_MASK;
return (number.dval);
}
}
#endif